import path from "path";
import { defineConfig } from "vite";
import { createVitePlugins } from "./build/index";

// import vue from "@vitejs/plugin-vue";
// import styleImport from "vite-plugin-style-import";
// import { configCompressPlugin } from "./build/compress";

// const VITE_BUILD_COMPRESS = "gzip"; //可选项 gzip,brotli,none 多个用逗号分隔
// const VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE = false;

const IS_BUILD = ["production", "prod"].includes(process.env.NODE_ENV);
const subDomain = "web";

export default defineConfig({
  base: "./", // 打包后访问静态资源目录设置为相对当前项目文件夹
  // plugins: [
  //   vue(),
  //   styleImport({
  //     libs: [
  //       {
  //         libraryName: "vant",
  //         esModule: true,
  //         resolveStyle: (name) => `vant/es/${name}/style`,
  //       },
  //     ],
  //   }),
  //   configCompressPlugin(
  //     VITE_BUILD_COMPRESS,
  //     VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE
  //   ),
  // ],
  plugins: createVitePlugins(IS_BUILD),
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "src"),
    },
  },
  server: {
    open: true,
    proxy: {
      "/api": {
        target: "https://testm.ninainfo.cn/",
        changeOrigin: true,
      },
    },
  },
  build: {
    terserOptions: {
      compress: {
        drop_console: true,
        drop_debugger: true,
      }, //生产环境时移除console
    },

    // rollupOptions: {
    //   input: {
    //     app1: path.resolve(__dirname, "src/pkgs/app1.html"),
    //     app2: path.resolve(__dirname, "src/pkgs/app2.html"),
    //   },
    //   output: {
    //     dir: `../../spaweb/${subDomain}/`,
    //   },
    // }, //多页面应用模式开启这里的配置

    // outDir: `../../spaweb/${subDomain}/`,
  },
});
